var prefix = api + "/admin/dict";

$(function () {
	var datas = dictByType('dict_type')
	renderDictFilter('#systemFlag', 'dict_type')
	var addFlag = permissions.sys_dict_add
	var editFlag = permissions.sys_dict_edit
	var deleteFlag = permissions.sys_dict_del
	//没有新增权限的话删除新增按钮
	if (!addFlag) {
		$('#addBtn').remove()
	}
	var options = {
		url: prefix + "/page",
		updateUrl: "/pages/sysadm/dict/dictEdit",
		removeUrl: prefix + "/{id}",
		modalName: "字典类型",
		columns: [
			{
				title: "序号",
				formatter: function (value, row, index) {
					return $.table.serialNumber(index);
				}
			},
			{
				field: 'type',
				title: '类型',
				sortable: true,
			},
			{
				field: 'description',
				title: '描述'
			},
			{
				field: 'systemFlag',
				title: '字典类型',
				formatter: function (value, row, index) {
					return $.table.selectDictLabel(datas, value);
				}
			},
			{
				field: 'remarks',
				title: '备注信息'
			},
			{
				field: 'createTime',
				title: '创建时间',
				sortable: true,
			},
			{
				title: '操作',
				align: 'center',
				formatter: function (value, row, index) {
					var actions = [];
					if (row.systemFlag != 1 && editFlag) {
						actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
					}
					actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="detail(\'' + row.id + '\',\'' + row.systemFlag + '\',\'' + row.type + '\')"><i class="fa fa-list-ul"></i>字典项</a> ');
					if (row.systemFlag != 1 && deleteFlag) {
						actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
					}
					return actions.join('');
				}
			}]
	};
	$.table.init(options);
});

/*字典列表-详细*/
function detail(dictId, flag, type) {
	// var url = prefix + '/detail/' + dictId;
	var url = '/pages/sysadm/dict/dictItemList?id=' + dictId+'&flag=' + flag + "&type=" + type;
	$.modal.openTab("字典数据", url);
}